package models

import (
	"gorm.io/gorm"
	"types"
)

type Order struct {
	gorm.Model
	UserId   int     `gorm:"type:int(11);not null;comment:用户id" json:"user_id"`
	ShopId   int     `gorm:"type:int(11);not null;comment:商品id" json:"shop_id"`
	OrderNum string  `gorm:"type:varchar(30);not null;comment:订单编号" json:"order_num"`
	ShopName string  `gorm:"type:varchar(30);not null;comment:商品名称" json:"shop_name"`
	ShoPrice float64 `gorm:"type:decimal(10,2);not null;comment:商品价格" json:"sho_price"`
	OrderStu int     `gorm:"type:int(11);not null;comment:订单状态" json:"order_stu"`
	PayStu   int     `gorm:"type:int(11);not null;comment:支付状态" json:"pay_stu"`
}

// 创建订单
func (o *Order) OrderAdd() error {
	return types.Db.Create(&o).Error
}

// 删除订单
func (o *Order) OrderDelete() error {

	return types.Db.Where("id = ?", o.ID).Delete(&o).Error
}
